/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package crawler;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/**
 *
 * @author Sasi-Admin
 */
public class Server {
     public static void main(String[] args)  {
        try {
            //Document doc = Jsoup.connect("http://www.autolanka.com/Buy.asp?ad_category_id=&search=&Page=2#members").userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.120 Safari/535.2").get();
            HttpServer h = HttpServer.create(new InetSocketAddress(1234),1);
            h.createContext("/asd",new HttpHandler() {

                @Override
                public void handle(HttpExchange he) throws IOException {
                    try {
                        //       InputStream is = he.getRequestBody();
                      //read(is); // .. read the request body
                      //String response = "This is the response";
                      
                      //File f = new File ("C:\\Oracle\\DerpThink.jpg");
                               Robot r = new Robot();
                           BufferedImage bi = r.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
                   
                      he.getResponseHeaders().set("Content-Type", "image/jpeg");
                      he.sendResponseHeaders(200, 0);
                      
                           OutputStream os = he.getResponseBody();
                      
                           
                           ImageIO.write(bi, "jpg", os);
                           
                      
                      os.close();
                    } catch (AWTException ex) {
                        Logger.getLogger(Crawler.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });
            
            h.start();
////            Elements e = doc.select("font[class*=BuyDataFONT]");
////            
////            for (Iterator<Element> it = e.iterator(); it.hasNext();) {
////                Element element = it.next();
////                System.out.println(element.text());
////            }
        } catch (IOException ex) {
            Logger.getLogger(Crawler.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
}
